import os
import random
import struct
import sys
import logging
logging.info(sys.path)
logging.info(sys.path)

from commDriver.TS_CAN import *
import pytest
from pytest_assume.plugin import assume
import crcmod
import math
from eprogress import LineProgress
from threading import Thread
import hashlib
import xml.etree.ElementTree as ET



class ChangeVolt(Thread):
    def __init__(self,candriver, exit = False):
        Thread.__init__(self)
        self.candriver = candriver['power']          #can引用
        self.exit = exit
        self.start()
        
    def SetVolt(self):
        # 设置电压为6-18的随机值
        VoltNumber = random.randint(6, 18)
        self.candriver.set_vltage(VoltNumber)
        logging.warning(f'电压设置为 [{VoltNumber}] V')
        # 设置电压保持时间为1ms - 2000ms 的随机值
        WaitTime = random.randint(1,500)/1000
        time.sleep(WaitTime)
        logging.warning(f'电压保持时间为 [{WaitTime* 1000}] ms')

        return 

    def run(self):
        while self.exit == False:
            self.SetVolt()

    def set_stop(self):
        
        self.set_stop()